package collection;

import exception.CollectionEmptyException;

public class ListQueue<E> implements IQueue<E>{

	private SLinkedList<E> internalList = new SLinkedList<E>();
	
	public ListQueue(){}
	
	@Override
	public boolean isEmpty() 
	{
		return this.internalList.isEmpty();
	}

	@Override
	public int size() 
	{
		return this.internalList.size();
	}

	@Override
	public void enqueue(E element) 
	{
		this.internalList.addLast(this.internalList.createNode(element));
	}

	@Override
	public E dequeue() throws CollectionEmptyException 
	{
		if (isEmpty())
		{
			throw new CollectionEmptyException("Queue");
		}
		else
		{
			E retVal = this.internalList.getFirst().getElement();
			this.internalList.removeFirst();
			
			return retVal;
		}
	}

	@Override
	public E front() throws CollectionEmptyException 
	{
		if (isEmpty())
		{
			throw new CollectionEmptyException("Queue");
		}
		else
		{
			return this.internalList.getFirst().getElement();
		}
	}

	@Override
	public String toString()
	{
		return this.internalList.toString();
	}
}
